package com.eastmelon.blog.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

import com.eastmelon.basic.model.SystemContext;

import net.coobird.thumbnailator.Thumbnails;

public class uploadUtil {
	public static final String uploadPath = SystemContext.getRealPath()
			+ "/resources/upload";

	public static void uploadImage(InputStream is, String imageName,int imageWidth,int imageHeight) throws IOException {
		String imagePath=uploadPath+"/image/"+imageName;
		BufferedImage bi=ImageIO.read(is);
		Thumbnails.of(bi).forceSize(imageWidth, imageHeight).toFile(imagePath);
		/*
		 * FileUtils.copyInputStreamToFile(is, new File(imagePath)); 保存文件
		 */
	}
	public static void deleteImage( String imageName){
		String imagePath=uploadPath+"/image/"+imageName;
		new File(imagePath).delete();
	}

}
